#!/bin/bash
filepath=$1
st=$2
start_time=$(($st/3600)):$(($st/60)):$(($st%60))
end=$3
function handler(){
	timeAll=$(ffmpeg -i $filepath/$1 2>&1 | grep 'Duration'| cut -d ' ' -f 4|cut -d '.' -f 1)
	echo "all time is:$timeAll"
	secondTime=$(echo $timeAll| cut -d : -f3)
	minTime=`echo $timeAll| cut -d : -f2`
	hourTime=`echo $timeAll| cut -d : -f1`
	secondAll=$((10#${minTime}*60+10#${secondTime}+10#${hourTime}*3600))
	end_sed=$(($secondAll-$end))
	echo $start_time
	end_time=$(($end_sed/3600)):$(($end_sed/60)):$(($end_sed%60))
	echo $end_time
	#`ffmpeg -ss $start_time -to $end_time -i $filepath/$1 -vcodec copy $filepath/out/$1`
	`ffmpeg -ss $start_time -to $end_time -i $filepath/$1 -c copy $filepath/out/$1`

}
for filename in `ls $filepath`
do
	echo $filename
	handler $filename
done
